package com.hxk.ioText.byteIo.handleIo;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class DataIo {

	public static void main(String[] args) {
		DataOutputStream dos = null;
		DataInputStream dis = null;
		try {
			dos = new DataOutputStream(new FileOutputStream("d:/d.txt"));
			dos.writeInt(123);
			dos.writeDouble(0.123);
			dos.writeBoolean(true);
			dos.writeUTF("java 数据流");
			dos.writeChar('a');
			dis = new DataInputStream(new FileInputStream("d:/d.txt"));
			int n = dis.readInt();
			System.out.println(n);
			double d = dis.readDouble();
			System.out.println(d);
			boolean b = dis.readBoolean();
			System.out.println(b);
			String s = dis.readUTF();
			System.out.println(s);
			char c = dis.readChar();
			System.out.println(c);
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				if(dis != null) {
					dis.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				if(dos != null) {
					dos.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
